package com.kehutong.crm.message.admin;

import org.coraframework.authz.HasPermission;
import org.coraframework.inject.Inject;
import org.coraframework.json.JSONObject;
import org.coraframework.mvc.MvcAction;
import org.coraframework.mvc.http.Bean;
import org.coraframework.mvc.http.ReqMapping;
import org.coraframework.mvc.http.result.Result;
import com.kehutong.common.dto.UniformSendReqDto;
import com.kehutong.common.util.Token;
import com.kehutong.crm.message.entity.Message;
import com.kehutong.crm.message.service.MessageService;

/**
 * 管理后台-消息管理
 */
@MvcAction
@ReqMapping("/admin/crm/message")
public class MessageController {

    @Inject
    private MessageService messageService;

    @ReqMapping("/test")
    public Object test(UniformSendReqDto dto){
        return Result.success(messageService.wxchatSend(dto));
    }

    @HasPermission("crm:message:view")
    @ReqMapping("/list")
    public Object list(JSONObject jsonObject) {

        return messageService.list(jsonObject);
    }

    @HasPermission("crm:message:add")
    @Bean(newInstance=true, copy=true)
    @ReqMapping("/save")
    public Object save(Token token, Message message) {

        message.setReleaseUserId(token.getUuid());
        message.setReleaseUserName(token.getUsername());
        return messageService.save(message);
    }

    @HasPermission("crm:message:edit")
    @Bean(copy=true)
    @ReqMapping("/update")
    public Object update(Message message) {

        return messageService.update(message);
    }

    @HasPermission("crm:message:del")
    @ReqMapping("/delete")
    public Object delete(Message message) {

        return messageService.delete(message);
    }

    @ReqMapping("/get")
    public Object get(Message message) {

        return Result.success(message);
    }

}
